package br.praticas.projetoacademia.views;

import br.praticas.projetoacademia.dao.ContatoDao;
import br.praticas.projetoacademia.dao.EnderecoDao;
import br.praticas.projetoacademia.dao.InstrutorDao;
import br.praticas.projetoacademia.models.Contato;
import br.praticas.projetoacademia.models.Endereco;
import br.praticas.projetoacademia.models.Instrutor;
import br.praticas.projetoacademia.util.Check;
import java.util.ArrayList;
import java.util.List;

import javax.swing.JOptionPane;
import javax.swing.RowFilter;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableModel;
import javax.swing.table.TableRowSorter;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;


/**
 *
 * @author lucia
 * @since 03/09/2014
 * @see classe EnderecoDao
 * @see classe ContatoDao
 * @see classe InstrutorDao
 * @see classe instrutor
 */
public class InstrutorView1 extends javax.swing.JDialog {

    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel1 = new javax.swing.JLabel();
        Cep1 = new javax.swing.JTextField();
        Excluir = new javax.swing.JButton();
        Novo = new javax.swing.JButton();
        jLabel7 = new javax.swing.JLabel();
        Cancelar = new javax.swing.JButton();
        Alterar = new javax.swing.JButton();
        jLabel3 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        bairro = new javax.swing.JTextField();
        jLabel6 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        Pesquisa = new javax.swing.JTextField();
        jLabel5 = new javax.swing.JLabel();
        btPesquisaCliente = new javax.swing.JButton();
        celular = new javax.swing.JTextField();
        Nome = new javax.swing.JTextField();
        jLabel8 = new javax.swing.JLabel();
        jScrollPane2 = new javax.swing.JScrollPane();
        tabela = new javax.swing.JTable();
        jLabel10 = new javax.swing.JLabel();
        Salvar = new javax.swing.JButton();
        jLabel11 = new javax.swing.JLabel();
        Salario = new javax.swing.JTextField();
        cidade = new javax.swing.JTextField();
        cep = new javax.swing.JTextField();
        jLabel12 = new javax.swing.JLabel();
        jLabel13 = new javax.swing.JLabel();
        telefone = new javax.swing.JTextField();
        jLabel14 = new javax.swing.JLabel();
        email = new javax.swing.JTextField();
        jSeparator1 = new javax.swing.JSeparator();
        jSeparator2 = new javax.swing.JSeparator();
        jSeparator3 = new javax.swing.JSeparator();
        cpf = new javax.swing.JTextField();
        estado = new javax.swing.JTextField();
        numero = new javax.swing.JTextField();
        jLabel9 = new javax.swing.JLabel();
        rua = new javax.swing.JTextField();
        jLabel15 = new javax.swing.JLabel();

        jLabel1.setText("jLabel1");

        Cep1.setEditable(false);

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("Instrutor");

        Excluir.setIcon(new javax.swing.ImageIcon(getClass().getResource("/br/praticas/projetoacademia/imagens/Delete.png"))); // NOI18N
        Excluir.setText("Excluir");
        Excluir.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                ExcluirActionPerformed(evt);
            }
        });

        Novo.setIcon(new javax.swing.ImageIcon(getClass().getResource("/br/praticas/projetoacademia/imagens/Add.png"))); // NOI18N
        Novo.setText("Novo");
        Novo.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                NovoActionPerformed(evt);
            }
        });

        jLabel7.setText("Contato:");

        Cancelar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/br/praticas/projetoacademia/imagens/No.png"))); // NOI18N
        Cancelar.setText("Cancelar");
        Cancelar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                CancelarActionPerformed(evt);
            }
        });

        Alterar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/br/praticas/projetoacademia/imagens/Modify.png"))); // NOI18N
        Alterar.setText("Alterar");
        Alterar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                AlterarActionPerformed(evt);
            }
        });

        jLabel3.setText("Bairro:");

        jLabel2.setText("Endereço:");

        bairro.setEditable(false);
        bairro.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                bairroActionPerformed(evt);
            }
        });

        jLabel6.setText("Cep:");

        jLabel4.setText("Cidade:");

        jLabel5.setText("Uf:");

        btPesquisaCliente.setText("Pesquisar");
        btPesquisaCliente.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btPesquisaClienteActionPerformed(evt);
            }
        });

        celular.setEditable(false);
        celular.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                celularActionPerformed(evt);
            }
        });

        Nome.setEditable(false);

        jLabel8.setText("Nome:");

        tabela.setAutoCreateRowSorter(true);
        tabela.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "Nome", "Cpf", "Salario", "Cidade", "Rua", "Bairro", "Numero", "Cep", "Uf", "Celular", "Fixo", "Email"
            }
        ) {
            Class[] types = new Class [] {
                java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.Object.class, java.lang.String.class, java.lang.Object.class, java.lang.String.class, java.lang.String.class, java.lang.Object.class, java.lang.Object.class, java.lang.Object.class
            };
            boolean[] canEdit = new boolean [] {
                false, true, true, true, true, true, true, true, true, true, true, true
            };

            public Class getColumnClass(int columnIndex) {
                return types [columnIndex];
            }

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        tabela.setAutoResizeMode(javax.swing.JTable.AUTO_RESIZE_OFF);
        tabela.getTableHeader().setReorderingAllowed(false);
        jScrollPane2.setViewportView(tabela);

        jLabel10.setText("Cpf:");

        Salvar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/br/praticas/projetoacademia/imagens/Save.png"))); // NOI18N
        Salvar.setText("Salvar");
        Salvar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                SalvarActionPerformed(evt);
            }
        });

        jLabel11.setText("Salario:");

        Salario.setEditable(false);
        Salario.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                SalarioActionPerformed(evt);
            }
        });

        cidade.setEditable(false);

        cep.setEditable(false);

        jLabel12.setText("Celelular:");

        jLabel13.setText("Telefone Fixo:");

        telefone.setEditable(false);
        telefone.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                telefoneActionPerformed(evt);
            }
        });

        jLabel14.setText("Email:");

        email.setEditable(false);
        email.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                emailActionPerformed(evt);
            }
        });

        cpf.setEditable(false);

        estado.setEditable(false);
        estado.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                estadoActionPerformed(evt);
            }
        });

        numero.setEditable(false);
        numero.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                numeroActionPerformed(evt);
            }
        });

        jLabel9.setText("Número");

        rua.setEditable(false);
        rua.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                ruaActionPerformed(evt);
            }
        });

        jLabel15.setText("Rua:");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jSeparator2)
                .addGap(176, 176, 176))
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(Pesquisa)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(btPesquisaCliente))
                            .addGroup(layout.createSequentialGroup()
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                    .addGroup(layout.createSequentialGroup()
                                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                            .addComponent(celular, javax.swing.GroupLayout.PREFERRED_SIZE, 155, javax.swing.GroupLayout.PREFERRED_SIZE)
                                            .addComponent(jLabel12))
                                        .addGap(18, 18, 18)
                                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                            .addComponent(telefone, javax.swing.GroupLayout.PREFERRED_SIZE, 155, javax.swing.GroupLayout.PREFERRED_SIZE)
                                            .addComponent(jLabel13))
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                            .addComponent(jLabel14)
                                            .addComponent(email)))
                                    .addGroup(layout.createSequentialGroup()
                                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                            .addComponent(jLabel8)
                                            .addComponent(Nome, javax.swing.GroupLayout.PREFERRED_SIZE, 364, javax.swing.GroupLayout.PREFERRED_SIZE))
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                            .addComponent(jLabel10)
                                            .addGroup(layout.createSequentialGroup()
                                                .addComponent(cpf, javax.swing.GroupLayout.PREFERRED_SIZE, 121, javax.swing.GroupLayout.PREFERRED_SIZE)
                                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                                .addComponent(Salario, javax.swing.GroupLayout.PREFERRED_SIZE, 76, javax.swing.GroupLayout.PREFERRED_SIZE))))
                                    .addComponent(jLabel7)
                                    .addComponent(jLabel2)
                                    .addGroup(layout.createSequentialGroup()
                                        .addComponent(Cancelar)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(Excluir)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(Alterar)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(Novo)
                                        .addGap(94, 94, 94)
                                        .addComponent(Salvar)))
                                .addGap(18, 18, 18)))
                        .addContainerGap())
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                .addComponent(jLabel11, javax.swing.GroupLayout.PREFERRED_SIZE, 52, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(jSeparator3, javax.swing.GroupLayout.PREFERRED_SIZE, 544, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addComponent(jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, 545, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(0, 0, Short.MAX_VALUE))
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(cidade, javax.swing.GroupLayout.PREFERRED_SIZE, 118, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel4))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(rua, javax.swing.GroupLayout.PREFERRED_SIZE, 95, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel15))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(bairro, javax.swing.GroupLayout.PREFERRED_SIZE, 95, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel3))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(numero, javax.swing.GroupLayout.PREFERRED_SIZE, 95, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel9))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(cep, javax.swing.GroupLayout.PREFERRED_SIZE, 118, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel6, javax.swing.GroupLayout.PREFERRED_SIZE, 52, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(estado, javax.swing.GroupLayout.PREFERRED_SIZE, 50, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel5, javax.swing.GroupLayout.PREFERRED_SIZE, 55, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(17, 17, 17))
                    .addComponent(jScrollPane2)))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(24, 24, 24)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel8, javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jLabel10)
                        .addComponent(jLabel11)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(Nome)
                    .addComponent(cpf)
                    .addComponent(Salario, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel2)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jSeparator3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(5, 5, 5)
                        .addComponent(jLabel15)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(cidade, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(bairro, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(numero, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(rua, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jLabel7))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(9, 9, 9)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel6)
                            .addComponent(jLabel5)
                            .addComponent(jLabel9)
                            .addComponent(jLabel4)
                            .addComponent(jLabel3))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(estado, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(cep, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, 11, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jSeparator2, javax.swing.GroupLayout.PREFERRED_SIZE, 0, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel12)
                    .addComponent(jLabel13)
                    .addComponent(jLabel14))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(celular, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(telefone, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(email, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(35, 35, 35)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(btPesquisaCliente)
                    .addComponent(Pesquisa, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 189, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(21, 21, 21)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(Alterar)
                    .addComponent(Cancelar)
                    .addComponent(Novo)
                    .addComponent(Excluir)
                    .addComponent(Salvar))
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    Instrutor instrutor = new Instrutor();
    Contato contatos = new Contato();
    Endereco enderecos = new Endereco();
    InstrutorDao daoInstrutor = new InstrutorDao();
    EnderecoDao daoEndereco = new EnderecoDao();
    ContatoDao daoContato = new ContatoDao();
    List<Instrutor> listaModelInstrutor = new ArrayList<>();
    List<Endereco> listaModelEndereco = new ArrayList<>();
    List<Contato> listaModelContato = new ArrayList<>();
    String tipoCadastro;
    private static final Logger LOGGER = LogManager.getLogger(InstrutorView1.class);
    private static final Logger LOGGER_PADRAO = LogManager.getRootLogger();
            
  
            
    public InstrutorView1() {
        initComponents();
        setLocationRelativeTo(null);
        preencherTabela();
    }
     /**
     * Metodo que lista todos os instrutores em uma tabela, com seus respectivos dados.
     */
    private void preencherTabela() {
        String colunas[] = {"Nome", "CPF", "Salário", "Cidade","Rua","Bairro",
            "Número","Cep", "Uf", "Celular", "Fixo", "Email"};
        listaModelInstrutor = daoInstrutor.listarInstrutor();
        String dados[][] = new String[listaModelInstrutor.size()][12];
        //CARREGA OS DADOS DA LISTA NA TABELA
        int cont = listaModelInstrutor.size();
        for (int i = 0; i < cont; i++) {
            dados[i][0] = listaModelInstrutor.get(i).getNome();
            dados[i][1] = listaModelInstrutor.get(i).getCpf();
            dados[i][2] = listaModelInstrutor.get(i).getSalario();
            dados[i][3] = listaModelInstrutor.get(i).getEndereco().getCidade();
            dados[i][4] = listaModelInstrutor.get(i).getEndereco().getRua();
            dados[i][5] = listaModelInstrutor.get(i).getEndereco().getBairro();
            dados[i][6] = listaModelInstrutor.get(i).getEndereco().getNumero();
            dados[i][7] = listaModelInstrutor.get(i).getEndereco().getCep();
            dados[i][8] = listaModelInstrutor.get(i).getEndereco().getEstado();
            dados[i][9] = listaModelInstrutor.get(i).getContato().getCelular();
            dados[i][10] = listaModelInstrutor.get(i).getContato().getTelefoneFixo();
            dados[i][11] = listaModelInstrutor.get(i).getContato().getEmail();  
        }
        TableModel model = new DefaultTableModel(dados, colunas);
        tabela.setModel(model);
    }

     /**
     * Metodo que excluir um instrutor ao selecionar a linha da tabela e preciona o botao excuir.
     */
    private void ExcluirActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_ExcluirActionPerformed
        
        DefaultTableModel modelo = (DefaultTableModel) tabela.getModel();
        int index = tabela.getSelectedRow();
        instrutor = daoInstrutor.BuscarInstrutor(index);
        if (Check.checkNull(instrutor)) {
            JOptionPane.showConfirmDialog(null, "Voce tem certeza que deseja excluir o instrutor selecionado?", "?", JOptionPane.YES_NO_OPTION);
            daoInstrutor.remove(instrutor, contatos, enderecos);
            LOGGER.info("deletado");
            JOptionPane.showMessageDialog(null, "instrutor excluido com suscesso!");
            preencherTabela();
        } else {
            JOptionPane.showMessageDialog(this, "Erro ao Excluir!", "ERRO", JOptionPane.ERROR_MESSAGE);
        }
        
    }//GEN-LAST:event_ExcluirActionPerformed

    private void NovoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_NovoActionPerformed
        tipoCadastro = "novo";
        this.habilitarCampos();
    }//GEN-LAST:event_NovoActionPerformed
    /**
     * Metodo que limpa os dados da interface instrutor
     */
    private void limpar() {
        cpf.setText("");
        Nome.setText("");
        bairro.setText("");
        cidade.setText("");
        cep.setText("");
        estado.setText("");
        celular.setText("");
        telefone.setText("");
        email.setText("");
        Salario.setText("");
        rua.setText("");
        numero.setText("");
        
    }
    /**
     * Metodo que desabilita os campos e botoes da tela instrutor
     */
    protected void desabilitarCampos() {
        Nome.setEditable(false);
        cpf.setEditable(false);
        bairro.setEditable(false);
        cidade.setEditable(false);
        cep.setEditable(false);
        estado.setEditable(false);

        celular.setEditable(false);
        telefone.setEditable(false);
        email.setEditable(false);
        Salario.setEditable(false);
        rua.setEditable(false);
        numero.setEditable(false);
        Salvar.setEnabled(false);
    }
    /**
     * Metodo que habilita os dados da interface instrutor
     */
    private void habilitarCampos() {
        Nome.setEditable(true);
        cpf.setEditable(true);
        bairro.setEditable(true);
        cidade.setEditable(true);
        cep.setEditable(true);
        estado.setEditable(true);
        celular.setEditable(true);
        telefone.setEditable(true);
        email.setEditable(true);
        Salario.setEditable(true);
        rua.setEditable(true);
        numero.setEditable(true);
        Salvar.setEnabled(true);
    }
    private void CancelarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_CancelarActionPerformed
        dispose();
    }//GEN-LAST:event_CancelarActionPerformed

    /**
     * Metodo que altera os dados de um instrutor
     */
    private void AlterarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_AlterarActionPerformed
        DefaultTableModel modelo = (DefaultTableModel) tabela.getModel();
        int index = tabela.getSelectedRow();
        instrutor = daoInstrutor.BuscarInstrutor(index);
        this.Nome.setText(instrutor.getNome());
        this.cpf.setText(instrutor.getCpf());
        this.Salario.setText(instrutor.getSalario());
        this.bairro.setText(instrutor.getEndereco().getBairro());
        this.cidade.setText(instrutor.getEndereco().getCidade());
        this.cep.setText(instrutor.getEndereco().getEstado());
        this.estado.setText(instrutor.getEndereco().getEstado());
        this.rua.setText(instrutor.getEndereco().getRua());
        this.numero.setText(instrutor.getEndereco().getNumero());
        this.celular.setText(instrutor.getContato().getCelular());
        this.telefone.setText(instrutor.getContato().getEmail());
        this.email.setText(instrutor.getContato().getTelefoneFixo());
        tipoCadastro = "alterar";
        LOGGER.info("Instrutor editado");
        habilitarCampos();

    }//GEN-LAST:event_AlterarActionPerformed

    /**
     * Metodo busca pelo nome um instrutor
     */
    private void btPesquisaClienteActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btPesquisaClienteActionPerformed
        DefaultTableModel tabela = (DefaultTableModel) this.tabela.getModel();
        final TableRowSorter<TableModel> sorter = new TableRowSorter<TableModel>(tabela);
        this.tabela.setRowSorter(sorter);
        String text = Pesquisa.getText();
        sorter.setRowFilter(RowFilter.regexFilter(text, 1));
    }//GEN-LAST:event_btPesquisaClienteActionPerformed

    /**
     * Metodo que salva um instrutor no banco, onde prenche seus respectinos dados
     * esse metodo tambem altera os dados dos instrutores.
     * @see metodo AlterarActionPerformed
     */
    private void SalvarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_SalvarActionPerformed
        instrutor.setNome(this.Nome.getText());
        instrutor.setCpf(this.cpf.getText());
        instrutor.setSalario(this.Salario.getText());
        enderecos.setBairro(this.bairro.getText());
        enderecos.setCep(this.cidade.getText());
        enderecos.setRua(this.rua.getText());
        enderecos.setCidade(this.cidade.getText());
        enderecos.setEstado(this.estado.getText());
        enderecos.setNumero(this.numero.getText());
        contatos.setCelular(this.celular.getText());
        contatos.setEmail(this.telefone.getText());
        contatos.setTelefoneFixo(this.email.getText());
        instrutor.setEndereco(enderecos);
        instrutor.setContato(contatos);
        if (tipoCadastro.equals("novo")) {
            daoInstrutor.add(instrutor, contatos, enderecos);
            JOptionPane.showMessageDialog(null, "instrutor cadastrado com sucesso.", "Ok", JOptionPane.INFORMATION_MESSAGE);
            LOGGER.info("Instrutor salvo no banco");
            LOGGER_PADRAO.info("salvouuu");
        } else if (tipoCadastro.equals("alterar")) {
            daoInstrutor.update(instrutor, contatos, enderecos);
            JOptionPane.showMessageDialog(null, "instrutor editado com sucesso.", "Ok", JOptionPane.INFORMATION_MESSAGE);
            LOGGER.info("Ops foi editado,  salvou no banco");
            LOGGER_PADRAO.info("editadooo");
        }
        limpar();
        this.desabilitarCampos();
        this.preencherTabela();
    }//GEN-LAST:event_SalvarActionPerformed

    private void celularActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_celularActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_celularActionPerformed

    private void SalarioActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_SalarioActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_SalarioActionPerformed

    private void telefoneActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_telefoneActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_telefoneActionPerformed

    private void emailActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_emailActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_emailActionPerformed

    private void bairroActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bairroActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_bairroActionPerformed

    private void estadoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_estadoActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_estadoActionPerformed

    private void numeroActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_numeroActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_numeroActionPerformed

    private void ruaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_ruaActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_ruaActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {

        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new InstrutorView1().setVisible(true);
                //teste
            }
        });

    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton Alterar;
    private javax.swing.JButton Cancelar;
    protected javax.swing.JTextField Cep1;
    private javax.swing.JButton Excluir;
    protected javax.swing.JTextField Nome;
    private javax.swing.JButton Novo;
    protected javax.swing.JTextField Pesquisa;
    protected javax.swing.JTextField Salario;
    private javax.swing.JButton Salvar;
    protected javax.swing.JTextField bairro;
    private javax.swing.JButton btPesquisaCliente;
    protected javax.swing.JTextField celular;
    protected javax.swing.JTextField cep;
    protected javax.swing.JTextField cidade;
    protected javax.swing.JTextField cpf;
    protected javax.swing.JTextField email;
    protected javax.swing.JTextField estado;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel13;
    private javax.swing.JLabel jLabel14;
    private javax.swing.JLabel jLabel15;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JSeparator jSeparator1;
    private javax.swing.JSeparator jSeparator2;
    private javax.swing.JSeparator jSeparator3;
    protected javax.swing.JTextField numero;
    protected javax.swing.JTextField rua;
    private javax.swing.JTable tabela;
    protected javax.swing.JTextField telefone;
    // End of variables declaration//GEN-END:variables
}
